# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=cfengine
pkgver=3.19.0
pkgrel=0
pkgdesc="A systems administration tool for networks"
url="https://www.cfengine.com/"
arch="all"
license="GPL-3.0-only"
install="$pkgname.post-install"
makedepends="$depends_dev lmdb-dev openssl1.1-compat-dev bison flex-dev
	acl-dev pcre-dev linux-headers"
depends="procps"
subpackages="$pkgname-doc $pkgname-masterfiles::noarch"
source="https://cfengine-package-repos.s3.amazonaws.com/tarballs/cfengine-$pkgver.tar.gz
	https://cfengine-package-repos.s3.amazonaws.com/tarballs/cfengine-masterfiles-$pkgver.tar.gz"

_builddirmasterfiles="$srcdir"/cfengine-masterfiles-${pkgver%_p*}
options="!check" # testsuite shows some unknown errors

# secfixes:
#   3.12.2-r0:
#     - CVE-2019-9929

prepare() {
	default_prepare

	# Also extract masterfiles
	cd $srcdir
	tar xf $pkgname-masterfiles-$pkgver.tar.gz
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--with-pic \
		--prefix=/usr \
		--enable-fhs \
		--localstatedir=/var \
		--mandir=/usr/share/man \
		--with-lmdb \
		--without-pam
	make

	cd "$_builddirmasterfiles"
	./configure \
		--prefix=/var/lib/cfengine
	make
}

package() {
	make install DESTDIR="$pkgdir"

	# not FHS but the tools seems to require those
	install -d "$pkgdir"/var/lib/cfengine/bin
	for i in "$pkgdir"/usr/bin/*; do
		ln -s ../../../../usr/bin/${i##*/} "$pkgdir"/var/lib/cfengine/bin/
	done
}

masterfiles() {
	pkgdesc="Cfengine default masterfiles"
	depends="cfengine"

	cd "$_builddirmasterfiles"
	make install DESTDIR="$subpkgdir"
}

sha512sums="
ab3c8e58f5bde8913ff695c74ee1834f07ce34e65426a8553bc764b6e2a995b80a44c8c2eca6c8990c1ac21be0eaefcb7e29d050e671a13abda7221ee166621d  cfengine-3.19.0.tar.gz
59d5f6ecd1f7652cf0b83e0a0a7a1fa9d3a1a911bc9781d813ed7392718112fbd149cde1a6a0aae062a99c3846ec63a31afbd3067d92ef9aa319267ec7238c1e  cfengine-masterfiles-3.19.0.tar.gz
"
